import java.util.HashSet;

class Solution {
    public int lengthOfLongestSubstring(String s) {
        char[] arr = s.toCharArray();
        HashSet<Character> hashSet = new HashSet<>();
        int left = 0, right = 1;
        int len = 0;
        if (arr.length == 0) return 0;
        hashSet.add(arr[left]);
        while (right < arr.length) {
            if (hashSet.contains(arr[right])) {
                len = Math.max(right - left, len);
            }
            while (hashSet.contains(arr[right])) {
                hashSet.remove(arr[left++]);
            }
            hashSet.add(arr[right]);
            right++;
        }
        return Math.max(len, hashSet.size());
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.lengthOfLongestSubstring("abcdabcbb"));
    }
}